.row#search-scope.form-inline
  = hidden_field_tag :machine_id
  = hidden_field_tag :grid_id
  = hidden_field_tag :product_id
  .form-group.col-md-2
    .control-label
      = button_tag('选择终端', type: 'button', id: 'select_machines', class: 'btn btn-outline btn-primary')
    %p.form-control-static#select_machines_text
  .form-group.col-md-2
    .control-label
      = button_tag('选择格子', type: 'button', id: 'select_grids', class: 'btn btn-outline btn-primary form-control')
    %p.form-control-static#select_grids_text
  .form-group.col-md-2
    .control-label
      = button_tag('选择商品', type: 'button', id: 'select_products', class: 'btn btn-outline btn-primary form-control')
    %p.form-control-static#select_products_text
  .form-group.col-md-2
    %label{for: 'status'} 状态
    %select#status.form-control
      %option{value: ''} --请选择--
      %option{value: 'online'} 上线
      %option{value: 'offline'} 下线
  %a.btn.btn-primary.btn-outline#search 搜索
  %a.btn.btn-primary.btn-outline#reset 重置

= render partial: 'shared/cpanel/products_modal'
= render partial: 'shared/cpanel/machines_modal'
= render partial: 'shared/cpanel/grids_modal'

:javascript
  $(function(){
    new CPANEL.ProductsModal({
      modal_id: "select_products",
      modal_confirm_callback: function(data){
        $("#search-scope #product_id").val(data.id);
        $("#search-scope #select_products_text").html(data.name + "("+data.price+")");
      }
    });

    new CPANEL.MachinesModal({
      modal_id: "select_machines",
      modal_confirm_callback: function(data){
        $("#search-scope #machine_id").val(data.id);
        $("#search-scope #select_machines_text").html(data.name + "("+data.code+")");
      }
    });

    new CPANEL.GridsModal({
      modal_id: "select_grids",
      modal_confirm_callback: function(data){
        $("#search-scope #grid_id").val(data.id);
        $("#search-scope #select_grids_text").html(data.name + "("+data.code+")");
      }
    });

    $("#search-scope #search").click(function(){
      CPANEL.MachineGrids.DataTable.search();
    })

    $("#search-scope #reset").click(function(){
      CPANEL.MachineGrids.DataTable.search_reset();
      CPANEL.MachineGrids.DataTable.search();
    })
  });
